﻿using AuthCenter.API.Read.Application.Commands.Accouns;
using AuthCenter.API.Read.DTO;
using B.S.AuthCenter.Api.Read.Application.Command.Users;
using B.S.AuthCenter.Api.Read.DTOs;
using B.S.AuthCenter.Domain;
using B.S.AuthCenter.ErrorCount;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace B.S.AuthCenter.Api.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class UsersController : ControllerBase
    {
        IMediator mediator;

        public UsersController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        
        
        [HttpPost]
        [AllowAnonymous]
        public Task<ApiResult<LoginDTO>> Login(LoginUserCommand request)
        {
            var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var userName = HttpContext.User.FindFirst(ClaimTypes.Name)?.Value;
            var roleName = HttpContext.User.FindFirst(ClaimTypes.Role)?.Value;
            var customerValue = HttpContext.User.FindFirst("CustomClaimType")?.Value;
            var key=HttpContext.User.FindFirst("key")?.Value;
            return mediator.Send(request);
        }
        [HttpGet]
      
        public Task<ApiResult<List<UserDTO>>> GetUser([FromQuery] GetUserCommand request)
        {
            return mediator.Send(request);
        }
        [HttpGet]
        public Task<ApiResult<List<Cascaderitne>>> Getcascader([FromQuery]CascadeMenuCommand request)
        {
            return mediator.Send(request);
        }
    }
}
